<template>
    <div id="parts">
        <el-button v-if="unitId != '0'" @click="insertList" class="slot-btn-top" type="primary" size="small">添加</el-button>
        <el-table :data="listdata.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe border :height="tableHeight" :header-cell-style="getRowClass">
            <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
            <el-table-column prop="orderNum" label="订单号" sortable min-width="110"></el-table-column>
            <el-table-column prop="productName" label="产品名称" sortable min-width="200"></el-table-column>
            <el-table-column prop="num" label="订单数量" sortable min-width="100"></el-table-column>
            <el-table-column prop="createTime" label="下单时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="predictTime" label="期望到货时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="orderStateName" label="订单状态" sortable min-width="100"></el-table-column>
            <el-table-column prop="surePredictTime" label="确定到货时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="outStorageTime" label="起运时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="lastSignTime" label="最后签收时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="signTime" label="签收时间" sortable min-width="170"></el-table-column>
            <el-table-column fixed="right" label="操作" sortable align="center" min-width="80">
                <template slot-scope="scope">
                    <el-button v-if="unitId != '0'" @click="updateList(scope.row)" type="text" size="small">{{ scope.row.orderState == '0' ? '编辑' : (scope.row.orderState == '3' ? '签收' : '详情')}}</el-button>
                    <el-button v-if="unitId == '0'" @click="examineList(scope.row)" type="text" size="small">{{ scope.row.orderState == '0' ? '审核 ':(scope.row.orderState == '2' ? '起运 ' : '详情')}}</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                       :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize"
                       layout="total, sizes, prev, pager, next, jumper" :total="listdata.length"></el-pagination>

        <!-- 详情 -->
        <el-dialog :title="dialogTitle" width="75%" top="50px" :visible.sync="isDialog" :close-on-click-modal="false">
            <el-tabs v-model="activeName" @tab-click="handleClick" style="padding-bottom: 15px;">
                <el-tab-pane label="基本信息" name="1" :style="dialogHeight">
                    <h3 class="dialog-plate-title" style="margin-bottom: 20px"><span>基本信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="tableData" label-position="right" label-width="150px">
                        <el-form-item label="订单号"><el-input v-model="tableData.orderNum" :disabled="!tableDataDisable.orderNum"></el-input></el-form-item>
                        <el-form-item label="商品名称"><el-select v-model="tableData.product" :disabled="!tableDataDisable.product"><el-option v-for="item in productList" :key="item.id" :label="item.name" :value="item.id"></el-option></el-select></el-form-item>
                        <el-form-item label="订单数量"><el-input v-model="tableData.num" :disabled="!tableDataDisable.num"></el-input></el-form-item>
                        <el-form-item label="单位"><el-select v-model="tableData.unit" :disabled="!tableDataDisable.unit"><el-option v-for="item in unitList" :key="item.code" :label="item.name" :value="item.code"></el-option></el-select></el-form-item>
                        <el-form-item label="经销商"><el-input v-model="tableData.dealerName" :disabled="!tableDataDisable.dealerName"></el-input></el-form-item>
                        <el-form-item label="下单人"><el-input v-model="tableData.creatorName" :disabled="!tableDataDisable.creatorName"></el-input></el-form-item>
                        <el-form-item label="下单时间"><el-input v-model="tableData.createTime" :disabled="!tableDataDisable.createTime"></el-input></el-form-item>
                        <el-form-item label="期望到货时间"><el-date-picker v-model="tableData.predictTime"  :disabled="!tableDataDisable.predictTime" format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                    </el-form>

                    <h3 v-if="dialogTitle !== '订单下达'" class="dialog-plate-title" style="margin-bottom: 20px"><span>审核信息</span></h3>
                    <el-form v-if="dialogTitle !== '订单下达'" :inline="true" class="demo-form-inline" v-model="tableData" label-position="right" label-width="150px">
                        <el-form-item label="确定到货时间"><el-date-picker v-model="tableData.surePredictTime" :disabled="!tableDataDisable.surePredictTime"  format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="审核人"><el-input v-model="tableData.approverName" :disabled="!tableDataDisable.approverName" ></el-input></el-form-item>
                        <el-form-item label="审核时间"><el-input v-model="tableData.approveTime" :disabled="!tableDataDisable.approveTime" ></el-input></el-form-item>
                        <el-form-item label="审核结果"><el-select v-model="tableData.approveResult" :disabled="!tableDataDisable.approveResult" ><el-option :value="1" label="审核通过"></el-option><el-option :value="0" label="审核驳回"></el-option></el-select></el-form-item>
                        <el-form-item label="是否库存占用"><el-select v-model="tableData.isOccupiedStorage" :disabled="!tableDataDisable.isOccupiedStorage" ><el-option :value="0" label="否"></el-option><el-option :value="1" label="是"></el-option></el-select></el-form-item>
                    </el-form>
                    <el-form v-if="dialogTitle !== '订单下达'" v-model="tableData" label-position="right" label-width="150px"><el-form-item label="审核备注"><el-input v-model="tableData.approveRemark" :disabled="!tableDataDisable.approveRemark" type="textarea" style="width:98%"></el-input></el-form-item></el-form>

                    <h3 v-if="dialogTitle !== '订单下达'" class="dialog-plate-title" style="margin-bottom: 20px"><span>物流信息</span></h3>
                    <el-form v-if="dialogTitle !== '订单下达'" :inline="true" class="demo-form-inline" v-model="tableData" label-position="right" label-width="150px">
                        <el-form-item label="物流公司"><el-input v-model="tableData.logisticsCompany" :disabled="!tableDataDisable.logisticsCompany"></el-input></el-form-item>
                        <el-form-item label="运单号"><el-input v-model="tableData.logisticsNum" :disabled="!tableDataDisable.logisticsNum"></el-input></el-form-item>
                        <el-form-item label="起运人"><el-input v-model="tableData.logisticsPerson" :disabled="!tableDataDisable.logisticsPerson"></el-input></el-form-item>
                        <el-form-item label="起运时间"><el-date-picker v-model="tableData.outStorageTime" :disabled="!tableDataDisable.outStorageTime" format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="最后签收时间"><el-date-picker v-model="tableData.lastSignTime" :disabled="!tableDataDisable.lastSignTime" format="yyyy-MM-dd HH:ss:mm" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="签收时间"><el-date-picker v-model="tableData.signTime" :disabled="!tableDataDisable.signTime" format="yyyy-MM-dd HH:ss:mm" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="签收人"><el-input v-model="tableData.signPerson" :disabled="!tableDataDisable.signPerson"></el-input></el-form-item>
                    </el-form>

                    <div class="dialog-footer" style="text-align: right;"><el-button @click="submitList" type="primary">确 定</el-button></div>

                </el-tab-pane>
                <el-tab-pane v-if="dialogTitle !== '订单下达'" label="散点图" name="2" :style="dialogHeight">
                    <el-form :inline="true" class="demo-form-inline" v-model="scatterList" label-position="right"
                                        label-width="130px" style="margin-bottom: 20px;margin-left: 50px">
                    <el-date-picker
                            v-model="scatterList.dateTime"
                            type="datetimerange"
                            :picker-options="pickerOptions2"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            align="right">
                    </el-date-picker>
                    <el-button type="primary" @click="getScatterCharts">查询</el-button>
                </el-form>
                    <div id="chartScatter" ref="chartScatter" style="width: 100%;height: 600px;"></div>
                </el-tab-pane>
            </el-tabs>
        </el-dialog>


        <!-- 详情 -->
        <el-dialog title="订单详情" width="80%" top="50px" :visible.sync="isExamineDialog" :close-on-click-modal="false">
          <div :style="dialogHeight">
              <h3 class="dialog-plate-title" style="margin-bottom: 20px"><span>基本信息</span></h3>
              <el-form :inline="true" class="demo-form-inline" v-model="tableExamineData" label-position="right" label-width="150px">
                  <el-form-item label="订单号"><el-input v-model="tableExamineData.orderNum" :disabled="!tableExamineDataDisable.orderNum"></el-input></el-form-item>
                  <el-form-item label="商品名称"><el-select v-model="tableExamineData.product" :disabled="!tableExamineDataDisable.product"><el-option v-for="item in productList" :key="item.id" :label="item.name" :value="item.id"></el-option></el-select></el-form-item>
                  <el-form-item label="订单数量"><el-input v-model="tableExamineData.num" :disabled="!tableExamineDataDisable.num"></el-input></el-form-item>
                  <el-form-item label="单位"><el-select v-model="tableExamineData.unit" :disabled="!tableExamineDataDisable.unit"><el-option v-for="item in unitList" :key="item.code" :label="item.name" :value="item.code"></el-option></el-select></el-form-item>
                  <el-form-item label="经销商"><el-input v-model="tableExamineData.dealerName" :disabled="!tableExamineDataDisable.dealerName"></el-input></el-form-item>
                  <el-form-item label="下单人"><el-input v-model="tableExamineData.creatorName" :disabled="!tableExamineDataDisable.creatorName"></el-input></el-form-item>
                  <el-form-item label="下单时间"><el-input v-model="tableExamineData.createTime" :disabled="!tableExamineDataDisable.createTime"></el-input></el-form-item>
                  <el-form-item label="期望到货时间"><el-date-picker v-model="tableExamineData.predictTime"  :disabled="!tableExamineDataDisable.predictTime" format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
              </el-form>

              <h3 v-if="dialogTitle !== '订单下达'" class="dialog-plate-title" style="margin-bottom: 20px"><span>审核信息</span></h3>
              <el-form v-if="dialogTitle !== '订单下达'" :inline="true" class="demo-form-inline" v-model="tableExamineData" label-position="right" label-width="150px">
                  <el-form-item label="确定到货时间"><el-date-picker v-model="tableExamineData.surePredictTime" :disabled="!tableExamineDataDisable.surePredictTime"  format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                  <el-form-item label="审核人"><el-input v-model="tableExamineData.approverName" :disabled="!tableExamineDataDisable.approverName" ></el-input></el-form-item>
                  <el-form-item label="审核时间"><el-input v-model="tableExamineData.approveTime" :disabled="!tableExamineDataDisable.approveTime" ></el-input></el-form-item>
                  <el-form-item label="审核结果"><el-select v-model="tableExamineData.approveResult" :disabled="!tableExamineDataDisable.approveResult" ><el-option :value="1" label="审核通过"></el-option><el-option :value="0" label="审核驳回"></el-option></el-select></el-form-item>
                  <el-form-item label="是否库存占用"><el-select v-model="tableExamineData.isOccupiedStorage" :disabled="!tableExamineDataDisable.isOccupiedStorage" ><el-option :value="0" label="否"></el-option><el-option :value="1" label="是"></el-option></el-select></el-form-item>
              </el-form>
              <el-form v-if="dialogTitle !== '订单下达'" v-model="tableExamineData" label-position="right" label-width="150px"><el-form-item label="审核备注"><el-input v-model="tableExamineData.approveRemark" :disabled="!tableExamineDataDisable.approveRemark" type="textarea" style="width:98%"></el-input></el-form-item></el-form>

              <h3 v-if="dialogTitle !== '订单下达'" class="dialog-plate-title" style="margin-bottom: 20px"><span>物流信息</span></h3>
              <el-form v-if="dialogTitle !== '订单下达'" :inline="true" class="demo-form-inline" v-model="tableExamineData" label-position="right" label-width="150px">
                  <el-form-item label="物流公司"><el-input v-model="tableExamineData.logisticsCompany" :disabled="!tableExamineDataDisable.logisticsCompany"></el-input></el-form-item>
                  <el-form-item label="运单号"><el-input v-model="tableExamineData.logisticsNum" :disabled="!tableExamineDataDisable.logisticsNum"></el-input></el-form-item>
                  <el-form-item label="起运人"><el-input v-model="tableExamineData.logisticsPerson" :disabled="!tableExamineDataDisable.logisticsPerson"></el-input></el-form-item>
                  <el-form-item label="起运时间"><el-date-picker v-model="tableExamineData.outStorageTime" :disabled="!tableExamineDataDisable.outStorageTime" format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                  <el-form-item label="最后签收时间"><el-date-picker v-model="tableExamineData.lastSignTime" :disabled="!tableExamineDataDisable.lastSignTime" format="yyyy-MM-dd HH:ss:mm" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                  <el-form-item label="签收时间"><el-date-picker v-model="tableExamineData.signTime" :disabled="!tableExamineDataDisable.signTime" format="yyyy-MM-dd HH:ss:mm" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                  <el-form-item label="签收人"><el-input v-model="tableExamineData.signPerson" :disabled="!tableExamineDataDisable.signPerson"></el-input></el-form-item>
              </el-form>
          </div>
            <div class="dialog-footer" slot="footer" style="text-align: right;"><el-button @click="submitExamineList" type="primary">确 定</el-button></div>
        </el-dialog>

    </div>
</template>

<script>
    import echarts from 'echarts';
    export default {
        data() {
            let date = new Date();
            let end = date.setDate(new Date(date.setHours(0, 0, 0, 0)).getDate() + 14);
            return {
                pickerOptions2: {
                    shortcuts: [
                        {
                            text: '最近一周',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                picker.$emit('pick', [start, end]);
                            }
                        },
                        {
                            text: '最近一个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                picker.$emit('pick', [start, end]);
                            }
                        },
                        {
                            text: '最近三个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                picker.$emit('pick', [start, end]);
                            }
                        }
                    ]
                },
                menuId: sessionStorage.getItem('menuId'),
                tokenId: sessionStorage.getItem("tokenId"),
                unitId: sessionStorage.getItem("unitId"),
                currentPage: 1,
                pagesize: 10,
                activeName:'1',
                tableHeight: document.documentElement.clientHeight - (sessionStorage.getItem("unitId") == 0 ? 130 : 160 ),
                dialogHeight: {
                    height: document.documentElement.clientHeight - 230 + 'px',
                    minHeight: document.documentElement.clientHeight - 230 + 'px',
                    overflowY: 'auto',
                },
                listdata: [],
                productList: [],
                unitList: [],


                // 详情
                isDialog: false,
                dialogTitle:'',
                tableData:{
                    approveRemark: '',
                    approveResult: '',
                    approveTime: '',
                    approver: '',
                    approverName: '',
                    createTime: '',
                    creator: '',
                    creatorName: '',
                    dealer: '',
                    dealerName: '',
                    id: '',
                    isOccupiedStorage: '',
                    lastSignTime: '',
                    logisticsCompany: '',
                    logisticsNum: '',
                    logisticsPerson: '',
                    num: '',
                    orderNum: '',
                    orderState: '',
                    orderStateName: '',
                    outStorageTime: '',
                    predictTime: '',
                    product: '',
                    productName: '',
                    signPerson: '',
                    signPersonName: '',
                    signTime: '',
                    surePredictTime: '',
                    unit: '',
                    unitName: '',
                },
                tableDataDisable:{
                    approveRemark: false,
                    approveResult: false,
                    approveTime: false,
                    approver: false,
                    approverName: false,
                    createTime: false,
                    creator: false,
                    creatorName: false,
                    dealer: false,
                    dealerName: false,
                    id: false,
                    isOccupiedStorage: false,
                    lastSignTime: false,
                    logisticsCompany: false,
                    logisticsNum: false,
                    logisticsPerson: false,
                    num: false,
                    orderNum: false,
                    orderState: false,
                    orderStateName: false,
                    outStorageTime: false,
                    predictTime: false,
                    product: false,
                    productName: false,
                    signPerson: false,
                    signPersonName: false,
                    signTime: false,
                    surePredictTime: false,
                    unit: false,
                    unitName: false,
                },

                // 散点图
                scatterList: {
                    dateTime: [new Date(), end],
                },
                scatterCharts: [],
                chartScatter: null,

                isExamineDialog:false,
                tableExamineData:{
                    approveRemark: '',
                    approveResult: '',
                    approveTime: '',
                    approver: '',
                    approverName: '',
                    createTime: '',
                    creator: '',
                    creatorName: '',
                    dealer: '',
                    dealerName: '',
                    id: '',
                    isOccupiedStorage: '',
                    lastSignTime: '',
                    logisticsCompany: '',
                    logisticsNum: '',
                    logisticsPerson: '',
                    num: '',
                    orderNum: '',
                    orderState: '',
                    orderStateName: '',
                    outStorageTime: '',
                    predictTime: '',
                    product: '',
                    productName: '',
                    signPerson: '',
                    signPersonName: '',
                    signTime: '',
                    surePredictTime: '',
                    unit: '',
                    unitName: '',
                },
                tableExamineDataDisable:{
                    approveRemark: false,
                    approveResult: false,
                    approveTime: false,
                    approver: false,
                    approverName: false,
                    createTime: false,
                    creator: false,
                    creatorName: false,
                    dealer: false,
                    dealerName: false,
                    id: false,
                    isOccupiedStorage: false,
                    lastSignTime: false,
                    logisticsCompany: false,
                    logisticsNum: false,
                    logisticsPerson: false,
                    num: false,
                    orderNum: false,
                    orderState: false,
                    orderStateName: false,
                    outStorageTime: false,
                    predictTime: false,
                    product: false,
                    productName: false,
                    signPerson: false,
                    signPersonName: false,
                    signTime: false,
                    surePredictTime: false,
                    unit: false,
                    unitName: false,
                },

                //权限
                jurisdiction: {
                    orderNum: true,
                    product: true,
                    productName: true,
                    unit: true,
                    dealer: true,
                    dealerName: true,
                    creator: true,
                    creatorName: true,
                    createTime: true,
                    predictTime: true,
                    signPerson: true,
                }
            };
        },
        created() {
            this.getProduceData();
            this.getOrderData();
            this.queryCoedByType();
            this.getJurisdiction();
        },
        methods: {
            getJurisdiction() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/system/menu/getMenuAllSrc/' + _this.menuId + '?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    console.log( res.data   )
                    if (res.data.statusCode == 200) {
                        for (let i = 0; i < res.data.content.length; i++) {
                            let item = res.data.content[i];
                            _this.jurisdiction[item.component] = item.menuShow;
                        }
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getProduceData() {
                let _this = this;
                this.$http({
                    url: "/api/adscm/order/jyProduct/selectAll?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: {"X-Requested-With": "XMLHttpRequest"}
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.productList = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },
            queryCoedByType() {
                let _this = this;
                this.$http({
                    url: "/api/adscm/system/code/queryCoedByType/unit?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: {"X-Requested-With": "XMLHttpRequest"}
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.unitList = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },
            getOrderData() {
                let _this = this;
                this.$http({
                    url: "/api/adscm/order/jyOrder/selectBystate/0?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: {"X-Requested-With": "XMLHttpRequest"}
                }).then(function (res) {
                    console.log(res.data)
                    if (res.data.statusCode == 200) {
                        _this.listdata = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },

            // 新增
            insertList() {
                this.isDialog = true;
                this.dialogTitle = "订单下达";
                this.tableData = {
                    approveRemark: '',
                    approveResult: '',
                    approveTime: '',
                    approver: '',
                    approverName: '',
                    createTime: '',
                    creator: '',
                    creatorName: '',
                    dealer: '',
                    dealerName: '',
                    id: '',
                    isOccupiedStorage: '',
                    lastSignTime: '',
                    logisticsCompany: '',
                    logisticsNum: '',
                    logisticsPerson: '',
                    num: '',
                    orderNum: '',
                    orderState: '',
                    orderStateName: '',
                    outStorageTime: '',
                    predictTime: '',
                    product: '',
                    productName: '',
                    signPerson: '',
                    signPersonName: '',
                    signTime: '',
                    surePredictTime: '',
                    unit: '',
                    unitName: '',
                };
                this.tableDataDisable={
                    approveRemark: false,
                    approveResult: false,
                    approveTime: false,
                    approver: false,
                    approverName: false,
                    createTime: false,
                    creator: false,
                    creatorName: false,
                    dealer: false,
                    dealerName: false,
                    id: false,
                    isOccupiedStorage: false,
                    lastSignTime: false,
                    logisticsCompany: false,
                    logisticsNum: false,
                    logisticsPerson: false,
                    num: true,
                    orderNum: false,
                    orderState: false,
                    orderStateName: false,
                    outStorageTime: false,
                    predictTime: true,
                    product: true,
                    productName: true,
                    signPerson: false,
                    signPersonName: false,
                    signTime: false,
                    surePredictTime: false,
                    unit: true,
                    unitName: true,
                };
            },
            updateList(row) {
                console.log( row  )
                let _this = this;
                if ( row.orderState != '3' ) {
                    this.isDialog = true;
                    this.dialogTitle = row.orderState == '0' ? "编辑" : '详情';
                    this.tableData = row;
                    this.tableData.product = parseInt( this.tableData.product);
                    this.tableData.approveResult = this.tableData.approveResult ? parseInt(  this.tableData.approveResult) : '';
                    this.tableData.isOccupiedStorage = this.tableData.isOccupiedStorage ? parseInt(  this.tableData.isOccupiedStorage) : '';
                    this.tableDataDisable={
                        approveRemark: false,
                        approveResult: false,
                        approveTime: false,
                        approver: false,
                        approverName: false,
                        createTime: false,
                        creator: false,
                        creatorName: false,
                        dealer: false,
                        dealerName: false,
                        id: false,
                        isOccupiedStorage: false,
                        lastSignTime: false,
                        logisticsCompany: false,
                        logisticsNum: false,
                        logisticsPerson: false,
                        num: row.orderState == '0' ? true : false,
                        orderNum: false,
                        orderState: false,
                        orderStateName: false,
                        outStorageTime: false,
                        predictTime: row.orderState == '0' ? true : false,
                        product: row.orderState == '0' ? true : false,
                        productName: row.orderState == '0' ? true : false,
                        signPerson: false,
                        signPersonName: false,
                        signTime: false,
                        surePredictTime: false,
                        unit: row.orderState == '0' ? true : false,
                        unitName: true,
                    };
                } else if(row.orderState == '3') {
                    this.$alert('如果签收请点击确定', '确认签收', {
                        confirmButtonText: '确定',
                        callback: action => {
                            _this.$http({
                                url: "/api/adscm/order/jyOrder/signOrder/" + row.id + "?tokenId=" + _this.tokenId,
                                method: "get",
                                headers: {"X-Requested-With": "XMLHttpRequest"}
                            }).then(function (res) {
                                console.log( res.data )
                                if (res.data.statusCode == 200) {
                                    _this.getOrderData();
                                } else {
                                    _this.$message.error(res.data.desc);
                                }
                            }).catch(function (catchres) {
                                _this.$message.error("加载失败！请重新加载...");
                            });

                        }
                    });
                }
            },
            examineList( row ){
                console.log( row.orderState )
                this.isDialog = true;
                this.dialogTitle = "编辑";
                this.tableData = row;
                this.tableData.product = parseInt( this.tableData.product);
                this.tableData.approveResult = this.tableData.approveResult ? parseInt(  this.tableData.approveResult) : '';
                this.tableData.isOccupiedStorage = this.tableData.isOccupiedStorage ? parseInt(  this.tableData.isOccupiedStorage) : '';
                this.tableDataDisable={
                    approveRemark: row.orderState =='0' ? true : false,
                    approveResult: row.orderState =='0' ? true : false,
                    approveTime: false,
                    approver: false,
                    approverName: false,
                    createTime: false,
                    creator: false,
                    creatorName: false,
                    dealer: false,
                    dealerName: false,
                    id: false,
                    isOccupiedStorage: row.orderState =='0' ? true : false,
                    lastSignTime: false,
                    logisticsCompany: row.orderState =='2' ? true : false,
                    logisticsNum: row.orderState =='2' ? true : false,
                    logisticsPerson: row.orderState =='2' ? true : false,
                    num: false,
                    orderNum: false,
                    orderState: false,
                    orderStateName: false,
                    outStorageTime: false,
                    predictTime: false,
                    product: false,
                    productName: false,
                    signPerson: false,
                    signPersonName: false,
                    signTime: false,
                    surePredictTime:  row.orderState =='0' ? true : false,
                    unit: false,
                    unitName: true,
                };
            },
            submitList() {
                let _this = this;
                let url;
                if (this.dialogTitle === "订单下达") {
                    url = "/api/adscm/order/jyOrder/insert?tokenId=" + _this.tokenId;
                } else if (this.dialogTitle === "编辑") {
                    url = "/api/adscm/order/jyOrder/update?tokenId=" + _this.tokenId;
                }

                _this.tableData.predictTime = _this.timestampToTime(_this.tableData.predictTime);
                _this.tableData.surePredictTime = _this.timestampToTime(_this.tableData.surePredictTime);
                _this.tableData.signTime = _this.timestampToTime(_this.tableData.signTime);
                _this.tableData.lastSignTime = _this.timestampToTime(_this.tableData.lastSignTime);
                console.log( _this.tableData )
                this.$http({
                    url: url,
                    method: "post",
                    headers: {"X-Requested-With": "XMLHttpRequest"},
                    data: _this.tableData
                }).then(function (res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.isDialog = false;
                        _this.getOrderData();
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },



            // 图
            getScatterCharts() {
                let _this = this;
                let start = _this.timestampToTime(_this.scatterList.dateTime[0]);
                let end = _this.timestampToTime(_this.scatterList.dateTime[1]);
                this.$http({
                    url: "/api/adscm/order/jyOrderChart/selectOrderChart/" + start + "/" + end + "?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: {"X-Requested-With": "XMLHttpRequest"}
                }).then(function (res) {
                    console.log(res.data)
                    if (res.data.statusCode == 200) {
                        _this.scatterCharts = res.data.content;
                        _this.drawScatter();
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },
            drawScatter() {
                let _this = this;
                this.chartScatter = echarts.init(document.getElementById('chartScatter'));
                let xAxisData = [], yAxisData = [], seriesData = [];
                for (let i = 0; i < _this.scatterCharts.length; i++) {
                    let item = _this.scatterCharts[i];
                    xAxisData.push(item.predictTime.substr(0, 10));
                    yAxisData.push(item.dealer);
                    seriesData.push({
                        type: 'scatter',
                        name: item.state == 0 ? '未审核' : '已审核',
                        symbolSize: item.state == 0 ? 20 : 15,
                        data: [[item.predictTime.substr(0, 10), item.dealer, 10, item.id, item.orderTime]]
                    })
                }
                this.chartScatter.clear();
                this.chartScatter.setOption({
                    grid: {
                        left: 150,
                        right: 10,
                        bottom: 65,
                        top: 50
                    },
                    legend: {
                        data: ['未审核', '已审核']
                    },
                    tooltip: {
                        triggerOn: "click",
                        formatter: function (params) {
                            console.log(params);
                            _this.updateExamineDialog(params.data[3]);
                        }
                    },
                    xAxis: {
                        data: _this.unique(xAxisData),
                        splitLine: {
                            lineStyle: {
                                type: 'dashed'
                            }
                        }
                    },
                    yAxis: {
                        data: _this.unique(yAxisData),
                        splitLine: {
                            lineStyle: {
                                type: 'dashed'
                            }
                        }
                    },
                    dataZoom: [
                        {
                            type: 'slider',
                            show: true,
                        },
                        {
                            type: 'inside',
                        },
                    ],
                    series: seriesData
                });
            },

            updateExamineDialog(id) {
                this.isExamineDialog = true;
                this.getExamineData(id);
            },
            getExamineData(id) {
                let _this = this;
                this.$http({
                    url: "/api/adscm/order/jyOrder/selectById/"+id+"?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: {"X-Requested-With": "XMLHttpRequest"}
                }).then(function (res) {
                    console.log(res.data)
                    if (res.data.statusCode == 200) {
                        _this.tableExamineData = res.data.content;
                        _this.tableExamineData.product = parseInt( _this.tableExamineData.product);
                        _this.tableExamineData.approveResult = _this.tableExamineData.approveResult ? parseInt(  _this.tableExamineData.approveResult) : '';
                        _this.tableExamineData.isOccupiedStorage = _this.tableExamineData.isOccupiedStorage ? parseInt(  _this.tableExamineData.isOccupiedStorage) : '';

                        _this.tableExamineDataDisable = {
                            approveRemark: _this.tableExamineData.orderState =='0' ? true : false,
                            approveResult: _this.tableExamineData.orderState =='0' ? true : false,
                            approveTime: false,
                            approver: false,
                            approverName: false,
                            createTime: false,
                            creator: false,
                            creatorName: false,
                            dealer: false,
                            dealerName: false,
                            id: false,
                            isOccupiedStorage: _this.tableExamineData.orderState =='0' ? true : false,
                            lastSignTime: false,
                            logisticsCompany: _this.tableExamineData.orderState =='2' ? true : false,
                            logisticsNum: _this.tableExamineData.orderState =='2' ? true : false,
                            logisticsPerson: _this.tableExamineData.orderState =='2' ? true : false,
                            num: false,
                            orderNum: false,
                            orderState: false,
                            orderStateName: false,
                            outStorageTime: false,
                            predictTime: false,
                            product: false,
                            productName: false,
                            signPerson: false,
                            signPersonName: false,
                            signTime: false,
                            surePredictTime:  _this.tableExamineData.orderState =='0' ? true : false,
                            unit: false,
                            unitName: true,
                        };
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },
            submitExamineList() {
                let _this = this;
                _this.tableExamineData.predictTime = _this.timestampToTime(_this.tableExamineData.predictTime);
                _this.tableExamineData.surePredictTime = _this.timestampToTime(_this.tableExamineData.surePredictTime);
                _this.tableExamineData.signTime = _this.timestampToTime(_this.tableExamineData.signTime);
                _this.tableExamineData.lastSignTime = _this.timestampToTime(_this.tableExamineData.lastSignTime);
                console.log( _this.tableExamineData )
                this.$http({
                    url: "/api/adscm/order/jyOrder/update?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: {"X-Requested-With": "XMLHttpRequest"},
                    data: _this.tableExamineData
                }).then(function (res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.isExamineDialog = false;
                        _this.getScatterCharts();
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },


            handleClick(tab, event) {
                if (tab.name === '2') {
                    this.getScatterCharts();
                }
            },
            handleSizeChange: function (size) {
                this.pagesize = size;
            },
            handleCurrentChange: function (currentPage) {
                this.currentPage = currentPage;
            },
            timestampToTime(timestamp) {
                if (timestamp) {
                    let date = new Date(timestamp);
                    let Y = date.getFullYear() + "-";
                    let M =
                        (date.getMonth() + 1 < 10
                            ? "0" + (date.getMonth() + 1)
                            : date.getMonth() + 1) + "-";
                    let D =
                        (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
                    let h =
                        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) +
                        ":";
                    let m =
                        (date.getMinutes() < 10
                            ? "0" + date.getMinutes()
                            : date.getMinutes()) + ":";
                    return timestamp ? Y + M + D + h + m + "00" : "";
                } else {
                    return "";
                }
            },
            unique(Array) {
                let res = [];
                let json = {};
                for (let i = 0; i < Array.length; i++) {
                    if (!json[Array[i]]) {
                        res.push(Array[i]);
                        json[Array[i]] = 1;
                    }
                }
                return res;
            },
        }
    };
</script>

<style scoped>
    #parts .el-table--small {
        font-size: 13px;
    }

    #parts .el-table .cell,
    #parts .el-table th div {
        padding-left: 0;
        padding-right: 0;
    }

    #parts .el-tab-pane.dialog1 .el-form {
        margin-bottom: 30px;
    }
</style>
